package com.sky.mapper.admin;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Setmeal;
import com.sky.pojo.ShoppingCart;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 套餐数据层
 */
@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     *
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 查询套餐是否有该菜品
     *
     * @param ids
     */
    Integer findDishes(List<Long> ids);

    /**
     * 新增套餐
     *
     * @param setmeal
     */
    // 主键回显
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @AutoFill(OperationType.INSERT)
    @Insert(" insert into setmeal(category_id, name, price, status, description, image, create_time,\n" +
            "                            update_time, create_user, update_user, make_time) values\n" +
            "        (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},\n" +
            "         #{updateTime},#{createUser},#{updateUser},#{makeTime})")
    void insertSetmeal(Setmeal setmeal);

    /**
     * 套餐分页查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> listSetmeal(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 删除套餐
     *
     * @param ids
     */
    void deleteSetmeal(List<Long> ids);

    /**
     * 检测套餐状态
     *
     * @param ids
     * @return
     */
    Integer seleteStatus(List<Long> ids, Integer status);

    /**
     * 根据id查询套餐
     *
     * @param id
     * @return
     */
    SetmealVO seleteSetmealById(Long id);

    /**
     * 修改套餐
     *
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    /**
     * 起售停售状态
     *
     * @param status
     * @param id
     */
    @Update("update setmeal set status = #{status} where id = #{id}")
    void updateSetmealStatus(Integer status, Long id);

    /**
     * 查询该id套餐下菜品是否有停售
     * @param id
     * @param status
     * @return
     */
    Integer selelctDishStatus(Long id, Integer status);

    /**
     * 检查套餐是否包含要停售的菜品
     * @param id
     * @return
     */
    List<Long> includesDisabledDish(Long id);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);


    /**
     * 查看购物车
     * @return
     */
    @Select("select id, name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time from shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> listShoppingCart(Long currentId);


}
